﻿using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace FinalYear.iNavigate.Classes
{
    /// <summary>
    /// Equation of the line between a point in frame T and T + 1
    /// </summary>
    public class LineEquation
    {
        public int gradient { get; set; }

        public int intersect { get; set; }

        public PointF startPoint { get; set; }

        public PointF endPoint { get; set; }
    }

    public class LineEquations : List<LineEquation>
    {
        public PointF FOE()
        {
            Dictionary<PointF, int> frequency = new Dictionary<PointF, int>();

            for (int i = 0; i < this.Count(); i++)
            {
                for (int j = 0; j < this.Count(); j++)
                {
                    if (j != i)
                    {
                        if (this[i].gradient != this[j].gradient)
                        {
                            LineEquation[] array = new LineEquation[2];
                            array[0] = this[i];
                            array[1] = this[j];
                            PointF p1 = new PointF();
                            p1.X = this[i].intersect - this[j].intersect / -(this[i].gradient - this[j].gradient);
                            p1.Y = this[i].gradient * p1.X + this[i].intersect;
                            if (frequency.Count() > 0)
                            {
                                if (frequency.ContainsKey(p1))
                                {
                                    frequency[p1] = frequency[p1]++;
                                }
                                else
                                {
                                    frequency.Add(p1, 1);
                                }
                            }
                            else
                            {
                                frequency.Add(p1, 1);
                            }
                        }
                    }
                }
            }

            return new PointF();
        }
    }
}